package com.titaniume.rqbbitmq.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

/**
 * @program: rqbbitmq-hello
 * @description: 消费者01 direct
 * @author: titaniume
 * @create: 2021-12-22 13:27
 */
public class ReceiveLogsDirect01 {

    public static final String EXCHANGE_NAME ="direct_logs";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        String queueName ="console";
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare(queueName,false,false,false,null);
        channel.queueBind(queueName,EXCHANGE_NAME,"info");
        channel.queueBind(queueName,EXCHANGE_NAME,"warning");
        System.out.println("等待接收消息......");
        //接收消息
        DeliverCallback deliverCallback =  (consumerTag,message) ->{
            String msg = new String(message.getBody(), "UTF-8");
            System.out.println("ReceiveLogsDirect01控制台打印接收到的消息:" + msg);
        };
        channel.basicConsume(queueName,true,deliverCallback,consumerTag->{});
    }
}